package demo.using.api.baidu;

import demo.utils.StringUtil;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.RenderedImage;
import java.io.File;
import java.util.List;

/**
 * @author : GuoFei
 * @since : 2019/7/2 9:54
 */
public class TransImgToText {

    public static void copyToSysClipboardText() throws Exception {
        Image image = StringUtil.getImageFromClipboard();
        File file = File.createTempFile("4578", "555");
        ImageIO.write( (RenderedImage)image, "png", file);
        List<String> sample = BaiDuScanImg.sample(file.getPath());
        file.delete();
        StringBuilder stringBuilder = new StringBuilder();
        sample.forEach(s->{
            stringBuilder.append(s).append("\r\n");
        });
        StringUtil.setSysClipboardText(stringBuilder.toString());
    }
}
